package service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import dao.UserDao;
import entity.User;
import service.UserService;

@Service
@Transactional
public class UserServiceImpl implements UserService{

	
	@Autowired
	private UserDao userDao;
	
	@Transactional(readOnly=false)
	public void save(User user){
		User user1=new User();
		user1.setName("测试回滚");
		userDao.save(user);
	}
	
	@Transactional(readOnly=false)
	public void update1(User user){
		userDao.update(user);
	}
	
	@Override
	@Transactional(readOnly=false)
	public void delete(User user){
		userDao.delete(user);
	
	}
	
	@Override
	@Transactional(readOnly=false)
	public void delete(int id){
		User user=new User();
		user.setId(id);
		delete(user);
	}
	@Override
	@Transactional(readOnly=false)
	public void delete(int[] id) {
		for (int i : id) {
			delete(i);
		}
	}

	//查询方法定义为只读
	@Transactional(readOnly=true)
	public User findById(int id) {
		User user=new User();
		user.setName("测试只读");
		UserDao usertDao = null;
		usertDao.save(user);
		return userDao.findById(id);
	}

	
	@Override
	@Transactional(readOnly=true)
	public List<User> findAll() {
		// TODO Auto-generated method stub
		return userDao.findAll();
	}


		
	public int countAll() {
		return userDao.countAll();
	}

	public List<User> findAll1() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void save1(User user) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(User user) {
		// TODO Auto-generated method stub
		
	}

	public void delete1(User student) {
		// TODO Auto-generated method stub
		
	}
	
	
 

}
